package com.ada.spark.datasource

import org.apache.spark.SparkConf
import org.apache.spark.sql.{SaveMode, SparkSession}

/**
  * 数据源支持格式：json, parquet, jdbc, orc, libsvm, csv, text
  */
object LoadTest {
    def main(args: Array[String]): Unit = {
        //创建配置对象
        val conf: SparkConf = new SparkConf().setAppName("LoadTest").setMaster("local[*]")

        //创建SparkSql的环境对象
        val spark: SparkSession = SparkSession.builder().config(conf).getOrCreate();

        val peopleDF = spark.read.format("json").load("format/people.json")

        peopleDF.write.mode(SaveMode.Overwrite).format("parquet").save("hdfs://hadoop121:9000/namesAndAges.parquet")

        val sqlDF = spark.sql("SELECT * FROM parquet.`hdfs://hadoop121:9000/namesAndAges.parquet`")

        sqlDF.show()
    }
}
